home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / emsif24a.zip / EMSTEST3.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  48KB  |  1,187 lines

  1. /***************************************************************************
  2. *   emstest3.c                                                             *
  3. *   MODULE:  EMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.2                                                           *
  6. *   DATE:    12/01/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires emsif.h, testutil.h, and emstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.0A.                   *
  12. *                                                                          *
  13. *   Regression test and example for EMSIF. See EMSTEST.C for more info.    *
  14. *                                                                          *
  15. ***************************************************************************/
  16.  
  17. /*
  18. ** system includes <>
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <string.h>
  25.  
  26. /* include appropriate file according to compiler */
  27. #ifdef __TURBOC__
  28.  
  29. #include <alloc.h>
  30.  
  31. #else
  32.  
  33. #include <malloc.h>
  34.  
  35. #endif
  36.  
  37.  
  38. /*
  39. ** custom includes ""
  40. */
  41.  
  42. #include "testutil.h"
  43.  
  44. #include "emsif.h"
  45. #include "emstest.h"
  46.  
  47.  
  48. /*
  49. ** local #defines
  50. */
  51.  
  52. #define UCF         unsigned char far
  53. #define UCH         unsigned char huge
  54.  
  55. /*
  56. ** Define LMALLOC() and LFREE() to the appropriate functions, according to
  57. ** compiler.
  58. */
  59. #ifdef __TURBOC__
  60.  
  61. #define LMALLOC(kbytes)         farmalloc((((unsigned long) kbytes) * 1024L))
  62. #define LFREE(ptr)              farfree((ptr))
  63.  
  64. #else
  65.  
  66. #define LMALLOC(kbytes)         halloc((kbytes), 1024)
  67. #define LFREE(ptr)              hfree((ptr))
  68.  
  69. #endif
  70.  
  71. /*
  72. ** This macro is the same as TRIPLECHECK(), defined in EMSTEST.H, except that
  73. ** it calls functions which can handle a far pointer.
  74. */
  75. #define LTRIPLECHECK(fu, st, ex, fr1, fr2, fr3)                         \
  76.                          lfailcheck((fu), (st), (fr1), (fr2), (fr3));   \
  77.                          lweirdretchk((fu), (st), (fr1), (fr2), (fr3)); \
  78.                          lweirdcodechk((fu), (ex), (fr1), (fr2), (fr3))
  79.  
  80. /*
  81. ** Checks to see if a region of memory (possibly longer than 64K) is still
  82. ** incrementing word values, handles cleanup and exit if not.
  83. */
  84. #define WORDCHECK(buf, len, msg, start)                         \
  85.     if (lfarincwordcheck((buf), (len), (start)) != 0) {         \
  86.         printf("Copy corrupted %s.\n", (msg)); EMMfree(handle); \
  87.         LFREE(testbuf); exit(3); }
  88.  
  89. /*
  90. ** Check source and destination buffers, respectively.
  91. */
  92. #define SRCWORDCHECK(buf, len)    WORDCHECK(buf, len, "source buffer", 0)
  93. #define CPYWORDCHECK(buf, len)    WORDCHECK(buf, len, "copied bytes", 0)
  94.  
  95. /*
  96. ** Checks to see if a region of memory (possibly longer than 64K) is still
  97. ** filled with a given value, handles cleanup and exit if not.
  98. */
  99. #define MEMCHECK(buf, len, val)                           \
  100.     if (lfarmemcheck((UCF *) (buf), (len), (val)) != 0) { \
  101.         printf("Copy corrupted destination.\n");          \
  102.         EMMfree(handle); LFREE(testbuf); exit(3); }
  103.  
  104. /*
  105. ** Checks buffer for nonzero values.
  106. */
  107. #define ZEROCHECK(buf, len)       MEMCHECK(buf, len, '\0')
  108.  
  109.  
  110. /*
  111. ** misc: copyright strings, version macros, etc.
  112. */
  113.  
  114. /*
  115. ** typedefs
  116. */
  117.  
  118. /*
  119. ** global variables
  120. */
  121.  
  122. /* see EMSTEST.C for info */
  123. extern int testno;
  124. extern unsigned char far *frameptr[];
  125. extern char *gblmsg;
  126.  
  127.  
  128. /*
  129. ** static globals
  130. */
  131.  
  132. /*
  133. ** function prototypes
  134. */
  135.  
  136. static void do_nlongcopy_tests(void);
  137. static void do_ilongcopy_tests(void);
  138.  
  139. static void lfailcheck(char *function, int status, void far *tofree1,
  140.                                                      int tofree2, int tofree3);
  141. static void lnofailcheck(char *function, int status, void far *tofree1,
  142.                                                      int tofree2, int tofree3);
  143. static void lweirdretchk(char *function, int status, void far *tofree1,
  144.                                                      int tofree2, int tofree3);
  145. static void lweirdcodechk(char *function, int expected, void far *tofree1,
  146.                                                      int tofree2, int tofree3);
  147.  
  148.  
  149. /*
  150. ** functions
  151. */
  152.  
  153.  
  154. /***************************************************************************
  155. *   FUNCTION: DO_LONGCOPY_TESTS                                            *
  156. *                                                                          *
  157. *   DESCRIPTION:                                                           *
  158. *                                                                          *
  159. *       Central dispatching function for long copy tests.                  *
  160. *                                                                          *
  161. *   ENTRY:                                                                 *
  162. *                                                                          *
  163. *       Void.                                                              *
  164. *                                                                          *
  165. *   EXIT:                                                                  *
  166. *                                                                          *
  167. *       Void.                                                              *
  168. *                                                                          *
  169. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  170. *                                                                          *
  171. ***************************************************************************/
  172. void do_longcopy_tests(void)
  173. {
  174.     do_nlongcopy_tests();
  175.     do_ilongcopy_tests();
  176.     return;
  177. } /* end of do_longcopy_tests() */
  178.  
  179.  
  180. /***************************************************************************
  181. *   FUNCTION: DO_NLONGCOPY_TESTS  (STATIC)                                 *
  182. *                                                                          *
  183. *   DESCRIPTION:                                                           *
  184. *                                                                          *
  185. *       Tests EMSIF functions EMMcopyto() and EMMcopyfrom() with copies    *
  186. *       longer than one EMS page ( > 16384 bytes).                         *
  187. *                                                                          *
  188. *   ENTRY:                                                                 *
  189. *                                                                          *
  190. *       Void.                                                              *
  191. *                                                                          *
  192. *   EXIT:                                                                  *
  193. *                                                                          *
  194. *       Void.                                                              *
  195. *                                                                          *
  196. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  197. *                                                                          *
  198. ***************************************************************************/
  199. static void do_nlongcopy_tests(void)
  200. {
  201.     unsigned char far *testbuf;
  202.     int handle;
  203.     int status;
  204.     unsigned long ticks, totticks;
  205.     int loop;
  206.     unsigned long loop2;
  207.  
  208.     /* allocate memory to test against */
  209.     testbuf = (unsigned char far *) LMALLOC(80);
  210.     if (testbuf == (unsigned char far *) NULL)
  211.     {
  212.         printf("Cannot allocate test memory. Aborting.\n");
  213.         exit(1);
  214.     }
  215.  
  216.     /* now allocate some EMS to test with */
  217.     handle = test_EMMalloc(81920L);
  218.  
  219.     /* fill test buffer with incrementing word pattern */
  220.     lfarincwordfill(testbuf,